package com.xw.controller;

import com.mysql.cj.Session;
import com.xw.mapper.Mymapper;
import com.xw.pojo.User02;

import com.xw.service.Myservicec;
import com.xw.service.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;


@RestController  // 等价于Controller+RequestBody 而RequestBody返回json数据
@RequestMapping("mybatis")
public class ControolerJDBC {


@Autowired
private Mymapper mymapper;

@Autowired
private Service service;

@Autowired
private Myservicec myservicec;


    @GetMapping ("find")  //发起get请求
    public Object find(){
        List<User02>  rs=  mymapper.find();
        HashMap data = new HashMap();

        data.put("code",400);
        data.put("msg","你已成功访问数据！");
        data.put("data",rs);
        return   data;
    }

    @PostMapping("findjson")  //发起post请求
    public  List<User02>  findbyid(@RequestBody User02 user02){
          List<User02> rs =mymapper.findbyid(user02);
        System.out.println("我收到了微信小程序的json数据");
          return  rs;
    }



   @GetMapping("delete")
   //service层的事务回滚
    public void delete(){
       int id=3;
       service.delete(id);
    }



    @GetMapping ("{id}")
    public Object find7(@PathVariable String id){
        Object rs = myservicec.find666(id);
        return   rs;
    }

}
